// 获取嵌套数组最大深度（用栈实现）

function getMaxDepth(arr) {
    if (!Array.isArray(arr)) return 0; // 非数组直接返回0
    const stack = [[arr, 1]];
    let maxDepth = 0;
    while (stack.length > 0) {
        const [currentArr, currentDepth] = stack.pop();
        if (currentDepth > maxDepth) {
            maxDepth = currentDepth;
        }
        for (const element of currentArr) {
            if (Array.isArray(element)) {
                stack.push([element, currentDepth + 1]);
            }
        }
    }
    return maxDepth;
}

console.log(getMaxDepth([])); // 1
console.log(getMaxDepth([1, [2, [3]], 4])); // 3
console.log(getMaxDepth([[[[]]]])); // 4
console.log(getMaxDepth([[[{name:3},[{name:4}]]]])); // 4